package com.ruoyi.system.mapper;

import com.ruoyi.system.domain.*;
import com.ruoyi.system.domain.vo.Nd_DevicesWrokStatus2;
import org.apache.ibatis.annotations.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 前端Api接口集合
 */
@Mapper
public interface Nd_ApiMapper {
    //region 鞋箱相关：清空鞋箱

    /**
     * 清空当前鞋箱的箱内设备，后面会马上再添加
     **/
    @Update("UPDATE nd_devices_work_status SET " +
            "Inbox_Id = 0," +
            "IsFree = 1," +
            "no_box_state = '出箱'," +
            "InOutBox = 1 " +
            "WHERE Inbox_Id = #{Device_Id}")
    void clearBox(@Param("Device_Id") String Device_Id);

    @Select("select * from nd_devices_work_status where Inbox_Id = #{Device_Id}")
    List<Nd_DevicesWrokStatus> queryInBoxDev(String deviceId);


    //endregion 鞋箱相关

    //region  防溜设备相关: 读出鞋箱内设备、更新单个设备状态、更新箱内多个设备

    /**
     * 读出鞋箱里当前有哪些设备
     */
    @Select("SELECT * FROM nd_devices_work_status WHERE Inbox_Id = #{Inbox_Id}")
    List<Nd_DevicesWrokStatus> selectDevicesByInbox_Id(@Param("Inbox_Id") String Inbox_Id);

    /**
     * 更新单个设备状态 for前端 nd_devices_work_status
     **/
    @Update("UPDATE nd_devices_work_status SET " +
            "Device_Code= #{devStatus.Device_Code}, " +
            "Device_VIN= #{devStatus.Device_VIN}, " +
            "Device_Type= #{devStatus.Device_Type}, " +
            "Track_Id= #{devStatus.Track_Id}, " +
            "Railway_CarNo= #{devStatus.Railway_CarNo}, " +
            "SortNo= #{devStatus.SortNo}, " +
            "Postion= #{devStatus.Postion}, " +
            "Person_Id= #{devStatus.Person_Id}, " +
            "Work_Type_Id= #{devStatus.Work_Type_Id}, " +
            "Operation_Type_Id= #{devStatus.Operation_Type_Id}, " +
//            "Vbat_Value= #{devStatus.Vbat_Value}, " +
            "OpenCloseBox= #{devStatus.OpenCloseBox}, " +
            "Inbox_Id= #{devStatus.Inbox_Id}, " +
            "Station_Id= #{devStatus.Station_Id}, " +
            "qbid= #{devStatus.qbid}, " +
            "create_by= #{devStatus.create_by}, " +
            "create_time= #{devStatus.create_time}, " +
            "update_by= #{devStatus.update_by}, " +
            "update_time= NOW(), " +
            "placement_time= #{devStatus.placement_time}, " +
            "no_box_state= #{devStatus.no_box_state} " +
//            "DevTemperature= #{devStatus.DevTemperature}, " +
//            "IsOnLine= #{devStatus.IsOnLine}"+
            "WHERE Device_Id = #{devStatus.Device_Id}")
    void updateDeviceStatus(@Param("devStatus") Nd_DevicesWrokStatus devStatus);


    /**
     * 更新单个设备状态 for前端 nd_devices_work_status
     **/
    @Update("UPDATE nd_devices_work_status SET " +
            "Track_Id= #{devStatus.Track_Id}, " +
            "Person_Id= #{devStatus.Person_Id}, " +
            "Work_Type_Id= #{devStatus.Work_Type_Id}, " +
            "Operation_Type_Id= #{devStatus.Operation_Type_Id}, " +
//            "Vbat_Value= #{devStatus.Vbat_Value}, " +
            "InOutBox= #{devStatus.InOutBox}, " +
            "OpenCloseBox= #{devStatus.OpenCloseBox}, " +
            "Inbox_Id= #{devStatus.Inbox_Id}, " +
            "no_box_state= #{devStatus.no_box_state}, " +
            "update_time = NOW(), " +
            "Station_Id= #{devStatus.Station_Id} " +
            "WHERE Device_Id = #{devStatus.Device_Id}")
    boolean manualOperationUpdateDeviceStatus(@Param("devStatus") Nd_DevicesWrokStatus devStatus);


    //endregion 防溜设备相关

    //region  精细查询相关：查设备ID、查询车站ID、查询车站人员

    /**
     * 根据铁鞋RFID和zmlm 查出设备ID
     */
    @Select("SELECT Device_Id FROM nd_devices INNER JOIN sys_dept ON nd_devices.Station_Id = sys_dept.dept_id WHERE Device_VIN = #{Device_VIN} AND sys_dept.zmlm = #{zmlm} ")
    String selectDeviceId(@Param("Device_VIN") String Device_VIN, @Param("zmlm") String zmlm);

    /**
     * 查询车站ID
     **/
    @Select("SELECT dept_id FROM sys_dept WHERE ZMLM=#{ZMLM}")
    String selectStationId(String ZMLM);

    /*
     * 查询部门所有人员  用户前台选择防溜人
     * */
//    @Select("SELECT * FROM sys_user WHERE dept_id = ")
    @Select("<script>" +
            "SELECT DISTINCT sys_user.user_id,sys_user.nick_name as user_name,sys_user.is_on_guard " +
            "FROM sys_user " +
            "JOIN sys_user_post ON sys_user.user_id = sys_user_post.user_id " +
            "WHERE sys_user.dept_id = #{Station_Id} " +
            "<if test='post_id != null and post_id != \"\"'>" +
            "  AND sys_user_post.post_id = #{post_id} " +
            "</if>" +
            "<if test='is_on_guard != 2'>" +
            "  AND sys_user.is_on_guard = #{is_on_guard} " +
            "</if>" +
            "</script>")
    List<Nd_User> getUsersByStationId(@Param("Station_Id") Integer Station_Id, @Param("post_id") Integer post_id, @Param("is_on_guard") int is_on_guard);
    //endregion  精细查询相关

    //region 报警相关： 添加报警记录，报警解除

    /**
     * 添加报警记录 nd_alarm_recorder
     * 报警值是1，就是插入，报警记录 是1报警，
     **/
    @Insert(
            "INSERT INTO nd_alarm_recorder (" +
                    "Device_Id, " +
                    "Alarm_Type, " +
                    "Alarm_Time," +
                    "IS_Relieve," +
                    "update_time," +
                    "Relieve_Mode," +
                    "Relieve_Reason," +
                    "update_by," +
                    "Anti_Recorder_Id," +
                    "beizhu," +
                    "Station_Id," +
                    "zmlm," +
                    "create_time" +
                    ") VALUES (" +
                    "#{Device_Id}, " +
                    "#{Alarm_Type}, " +
                    "#{Alarm_Time}, " +
                    "#{IS_Relieve}, " +
                    "#{update_time}, " +
                    "#{Relieve_Mode}, " +
                    "#{Relieve_Reason}, " +
                    "#{update_by}, " +
                    "#{Anti_Recorder_Id}, " +
                    "#{beizhu}, " +
                    "#{Station_Id}, " +
                    "#{zmlm}, " +
                    "#{create_time})"
    )
    void insertAlarmRecorder(Nd_AlarmRecorder devAlarm);

    /**
     * 报警解除 nd_alarm_recorder 是要更新该设备最新的同类报警信息的报警状态为0正常，同时更新解除方式，解除人，解除时间，
     */
    @Update("UPDATE nd_alarm_recorder " +
            "SET " +
            "IS_Relieve = #{IS_Relieve}, " +
            "Relieve_Mode = #{Relieve_Mode}," +
            "update_by = #{update_by}," +
            "update_time = #{update_time}" +
            "WHERE " +
            " nd_alarm_recorder.Alarm_Type = #{Alarm_Type}  " +
            " AND nd_alarm_recorder.IS_Relieve <> 1  " +
            " AND nd_alarm_recorder.Device_Id = #{Device_Id}")
    void updateAlarmRecorder(Nd_AlarmRecorder devAlarm);
    //endregion 报警相关

    //region 防溜台账相关：  添加防溜记录、

    /**
     * 添加防溜记录  nd_anti_running_recorder
     **/
    @Insert(
            "INSERT INTO nd_anti_running_recorder (" +
                    "Station_Id," +
                    "zmlm," +
                    "Track_Id," +
                    "Device_Id," +
                    "Railway_CarNo," +
                    "SortNo," +
                    "Postion," +
                    "Work_Type_Id," +
                    "Person_Id," +
                    "Operation_Type_Id," +
                    "zwh," +
                    "beizhu," +
                    "create_by," +
                    "create_time," +
                    "update_by," +
                    "update_time," +
                    "placement_time," +
                    "qbid" +
                    ") VALUES (" +
                    "#{Station_Id}," +
                    "UPPER(#{zmlm})," +
                    "#{Track_Id}," +
                    "#{Device_Id}," +
                    "#{Railway_CarNo}," +
                    "#{SortNo}," +
                    "#{Postion}," +
                    "#{Work_Type_Id}," +
                    "#{Person_Id}," +
                    "#{Operation_Type_Id}," +
                    "#{zwh}," +
                    "#{beizhu}," +
                    "#{create_by}," +
                    "#{create_time}," +
                    "#{update_by}," +
                    "#{update_time}," +
                    "#{placement_time}," +
                    "#{qbid}" +
                    ")"
    )
    void insertAntiRunningRecorder(Nd_AntiRunningRecorder devAnti);

    /**
     * 修改防溜台账
     *
     * @param devAnti
     * @return
     */
    @Update(
            "UPDATE nd_anti_running_recorder  " +
                    "SET " +
//                    "Station_Id = #{Station_Id}, " +
//                    "zmlm = #{zmlm} " +
//                    "Device_Id = #{Device_Id}, " +
//                    "Track_Id = #{Track_Id}, " +
                    "Railway_CarNo = #{Railway_CarNo}, " +
                    "SortNo = #{SortNo}, " +
                    "Postion = #{Postion}, " +
//                    "Work_Type_Id = #{}, " +
                    "Person_Id = #{Person_Id}, " +
                    "Operation_Type_Id = #{Operation_Type_Id}, " +
//                    "zwh = #{zwh}, " +
//                    "beizhu = #{beizhu}, " +
                    "placement_time = #{placement_time}, " +
                    "update_by = #{update_by}, " +
                    "update_time = #{update_time} " +
//                    "qbid = #{qbid}  " +
                    "WHERE " +
                    "qbid = #{qbid} and Device_Id = #{Device_Id} "
//                    "  Anti_Recorder_Id = ( " +
//                    "SELECT " +
//                    "  *  " +
//                    "FROM " +
//                    "  ( SELECT Anti_Recorder_Id FROM nd_anti_running_recorder WHERE qbid = #{qbid} and Device_Id = #{Device_Id} AND Track_Id = #{Track_Id} AND Work_Type_Id = 1 ORDER BY create_time DESC LIMIT 1 ) AS subquery  " +
    )
    Integer updateAntiRunningRecorder(Nd_AntiRunningRecorder devAnti);
    //endregion 防溜台账相关

    //region 股道或车辆相关：查询股道占用信息、添加接发车记录

    /**
     * 查询股道占用信息 nd_track
     **/
    @Select(" SELECT " +
            "nd.Track_Id," +
            "nd.Field_Id," +
            "nd.Track_Name," +
            "nd.Track_Number," +
            "nd.Track_Code," +
            "nd.zmlm," +
            "ndr_start.is_open," +
            "nd.Station_Id," +
            "( CASE WHEN ndr_start.dfrq IS NOT NULL AND ndr_end.dfrq IS NULL THEN ndr_start.cxms ELSE NULL END ) AS cxms," +
            "( CASE WHEN ndr_start.dfrq IS NOT NULL AND ndr_end.dfrq IS NULL THEN ndr_start.qbid ELSE NULL END ) AS qbid," +
            "( CASE WHEN ndr_start.dfrq IS NOT NULL AND ndr_end.dfrq IS NULL THEN ndr_start.cc ELSE NULL END ) AS cc," +
            "( CASE WHEN ndr_start.dfrq IS NOT NULL AND ndr_end.dfrq IS NULL THEN ndr_start.cls ELSE NULL END ) AS cls, " +
            "( CASE WHEN ndr_start.dfrq IS NOT NULL AND ndr_end.dfrq IS NULL THEN '1' ELSE '2' END ) AS dfbz, " +
            "ndr_start.dfrq AS start_time," +
            "ndr_end.dfrq AS end_time " +
            "FROM nd_track nd " +
            "LEFT JOIN nd_train_recoder ndr_start ON nd.Track_Id = ndr_start.Track_Id " +
            "AND ndr_start.dfbz = 1 " +
            "LEFT JOIN nd_train_recoder ndr_end ON nd.Track_Id = ndr_end.Track_Id " +
            "AND ndr_end.dfbz = 2 " +
            "AND ndr_end.dfrq = ( SELECT MIN( dfrq ) FROM nd_train_recoder WHERE Track_Id = nd.Track_Id AND dfbz = 2 AND dfrq > ndr_start.dfrq ) " +
            " WHERE " +
            "(ndr_start.dfrq = ( SELECT MAX( dfrq ) FROM nd_train_recoder WHERE Track_Id = nd.Track_Id AND dfbz = 1 ) OR ndr_start.dfrq IS NULL )" +
            "AND nd.Field_Id = #{Field_Id} " +
            "ORDER BY nd.Track_Id ")
    List<Nd_Track> getTracksByFieldId(@Param("Field_Id") String Field_Id);

    /**
     * 添加接发车记录  nd_train_recoder
     **/
    @Insert("INSERT INTO nd_train_recoder (" +
            "cc," +
            "Station_Id," +
            "zmlm," +
            "Track_Id," +
            "cls," +
            "dfbz," +
            "dfbrq," +
            "create_by," +
            "is_open," +
            "cxms" +
            ") VALUES (" +
            "#{nd_TrainRecoder.cc}," +
            "#{nd_TrainRecoder.Station_Id}," +
            "UPPER(#{nd_TrainRecoder.zmlm})," +
            "#{nd_TrainRecoder.Track_Id}," +
            "#{nd_TrainRecoder.cls}," +
            "#{nd_TrainRecoder.dfbz}," +
            "NOW()," +
            "#{nd_TrainRecoder.create_by}," +
            "#{nd_TrainRecoder.is_open}," +
            "#{nd_TrainRecoder.cxms}" +
            ")"
    )
    @Options(useGeneratedKeys = true, keyProperty = "nd_TrainRecoder.qbid")
    int insertTrainRecorder(@Param("nd_TrainRecoder") Nd_TrainRecoder nd_TrainRecoder);

    /*
     * 更新接发车记录
     * */
    @Update({
            "<script>",
            "UPDATE nd_train_recoder",
            "SET update_time = NOW()",
            "<if test='ndTrainRecoder.cc != null'>",
            ", cc = #{ndTrainRecoder.cc}",
            "</if>",
            "<if test='ndTrainRecoder.zmlm != null'>",
            ", zmlm = UPPER(#{ndTrainRecoder.zmlm})",
            "</if>",
            "<if test='ndTrainRecoder.cls != null'>",
            ", cls = #{ndTrainRecoder.cls}",
            "</if>",
            "<if test='ndTrainRecoder.is_open != null'>",
            ", is_open = #{ndTrainRecoder.is_open}",
            "</if>",
            "<if test='ndTrainRecoder.is_open != null'>",
            ", cls = #{ndTrainRecoder.is_open}",
            "</if>",
            "<if test='ndTrainRecoder.cxms != null'>",
            ", cxms = #{ndTrainRecoder.cxms}",
            "</if>",
            "WHERE qbid = #{ndTrainRecoder.qbid}",
            "</script>"
    })
    int updateTrainRecoder(@Param("ndTrainRecoder") Nd_TrainRecoder ndTrainRecoder);
    //endregion 股道及车辆相关

    //region 车站所有设备状态 及配置信息

    /**
     * 查询整个站的所有设备状态
     */
    @Select("SELECT * FROM nd_field WHERE Station_Id = #{Station_Id}")
    @Results({
            @Result(property = "Field_Id", column = "Field_Id"),
            //查询铁鞋 股道上 箱子里 游离区
            @Result(property = "Boxes", column = "Field_Id", many = @Many(select = "com.ruoyi.system.mapper.Nd_ApiMapper.getBoxesByFieldId")),
            //获取游离区铁鞋
            @Result(property = "FShoes", column = "Field_Id", many = @Many(select = "com.ruoyi.system.mapper.Nd_ApiMapper.getFDevicesByFieldId")),
            //获取股道上的铁鞋 +报警
            @Result(property = "PShoes", column = "Field_Id", many = @Many(select = "com.ruoyi.system.mapper.Nd_ApiMapper.getPDevicesByFieldId")),
            @Result(property = "Tracks", column = "Field_Id", many = @Many(select = "com.ruoyi.system.mapper.Nd_ApiMapper.getTracksByFieldId")),
            @Result(property = "FFasteners", column = "Field_Id", many = @Many(select = "com.ruoyi.system.mapper.Nd_ApiMapper.getFFsternerBoxByFieldId")),
            @Result(property = "PFasteners", column = "Field_Id", many = @Many(select = "com.ruoyi.system.mapper.Nd_ApiMapper.getPFsternerByFieldId")),
            @Result(property = "FSleepers", column = "Field_Id", many = @Many(select = "com.ruoyi.system.mapper.Nd_ApiMapper.getFSleepBoxByFieldId")),
            @Result(property = "PSleepers", column = "Field_Id", many = @Many(select = "com.ruoyi.system.mapper.Nd_ApiMapper.getPSleepByFieldId")),
            @Result(property = "nd_StationConfig", column = "Station_Id", one = @One(select = "com.ruoyi.system.mapper.Nd_ApiMapper.getStationConfig"))
    })
    List<Nd_Field> getFieldsByStationId(String Station_Id);

    //获取游离区的紧固器
    @Select("SELECT *,sys_user.user_name as Person_Name FROM nd_devices_work_status LEFT JOIN sys_user on nd_devices_work_status.Person_Id = sys_user.user_id " +
            "WHERE Device_Type = 3 AND default_box_id=#{defaultBoxId} ")
    List<Nd_DevicesWrokStatus> getFFsternerByFieldId(String defaultBoxId);

    //获取箱子里面的防溜枕木
    @Select("SELECT * FROM nd_devices_work_status WHERE Device_Type = 5 AND default_box_id=#{defaultBoxId} ")
    List<Nd_DevicesWrokStatus> getFSleepByFieldId(String defaultBoxId);

    //获取游离区的防溜枕木 箱子加上里面的鞋
    @Select("SELECT * FROM nd_devices_work_status WHERE Device_Type = 8 AND Field_Id=#{Field_Id} ")
    @Results({
            @Result(property = "Device_Id", column = "Device_Id"),
            @Result(property = "devices", column = "Device_Id", javaType = List.class,
                    many = @Many(select = "com.ruoyi.system.mapper.Nd_ApiMapper.getFSleepByFieldId"))
    })
    List<Nd_DevicesWrokStatus> getFSleepBoxByFieldId(String Field_Id);

    //获取紧固器箱子 加上里面的鞋
    @Select("SELECT * FROM nd_devices_work_status WHERE Device_Type = 7 AND Field_Id=#{Field_Id} ")
    @Results({
            @Result(property = "Device_Id", column = "Device_Id"),
            @Result(property = "devices", column = "Device_Id", javaType = List.class,
                    many = @Many(select = "com.ruoyi.system.mapper.Nd_ApiMapper.getFFsternerByFieldId"))
    })
    List<Nd_DevicesWrokStatus> getFFsternerBoxByFieldId(String Field_Id);


    //获取已经在股道上紧固器
    @Select("SELECT nd_devices_work_status.*,nd_track.Track_Number,nd_track.Track_Code,sys_user.user_name as Person_Name FROM nd_devices_work_status " +
            " LEFT JOIN nd_track ON nd_track.Track_Id = nd_devices_work_status.Track_Id " +
            " LEFT JOIN sys_user on nd_devices_work_status.Person_Id = sys_user.user_id " +
            " WHERE Device_Type = 3 AND InBox_Id = 0 AND nd_devices_work_status.Track_Id>0 AND nd_devices_work_status.Field_Id=#{Field_Id} ")
    List<Nd_DevicesWrokStatus> getPFsternerByFieldId(String Field_Id);

    //获取已经在股道上防溜枕木
    @Select("SELECT nd_devices_work_status.*,nd_track.Track_Number,nd_track.Track_Code,sys_user.user_name as Person_Name  FROM nd_devices_work_status " +
            " LEFT JOIN nd_track ON nd_track.Track_Id = nd_devices_work_status.Track_Id " +
            " LEFT JOIN sys_user on nd_devices_work_status.Person_Id = sys_user.user_id " +
            " WHERE Device_Type = 5 AND InBox_Id = 0 AND nd_devices_work_status.Track_Id > 0 AND nd_devices_work_status.Field_Id=#{Field_Id} ")
    List<Nd_DevicesWrokStatus> getPSleepByFieldId(String Field_Id);

    //获取铁鞋箱状态
    @Select("SELECT * FROM nd_devices_work_status WHERE Field_Id = #{Field_Id} AND Device_Type = 4")
    @Results({
            @Result(property = "Device_Id", column = "Device_Id"),
            @Result(property = "Attributes", column = "Device_Id", many = @Many(select = "com.ruoyi.system.mapper.Nd_ApiMapper.getAttributesByDeviceId")),
            @Result(property = "Shoes", column = "Device_Id", many = @Many(select = "com.ruoyi.system.mapper.Nd_ApiMapper.getDevicesByBoxId"))
    })
    List<Nd_BoxStatus> getBoxesByFieldId(String Field_Id);

    //获取箱子里的铁鞋
    @Select("SELECT * FROM nd_devices_work_status WHERE default_box_id = #{InBox_Id} or Inbox_Id = #{InBox_Id} ")
    @Results({
            @Result(property = "Device_Id", column = "Device_Id"),
            @Result(property = "Attributes", column = "Device_Id", many = @Many(select = "com.ruoyi.system.mapper.Nd_ApiMapper.getAttributesByDeviceId"))
    })
    List<Nd_DevicesWrokStatus> getDevicesByBoxId(String InBox_Id);

    //获取游离区的铁鞋
//    @Select("SELECT *,sys_user.user_name as Person_Name  FROM nd_devices_work_status" +
//            " LEFT JOIN sys_user on nd_devices_work_status.Person_Id = sys_user.user_id " +
//            " WHERE Device_Type = 2 AND InBox_Id = 0 AND Track_Id=0 AND Field_Id=#{Field_Id} ")
   @Select("SELECT *,sys_user.user_name as Person_Name  FROM nd_devices_work_status" +
            " LEFT JOIN sys_user on nd_devices_work_status.Person_Id = sys_user.user_id " +
            " WHERE (Device_Type = 2 or Device_Type = 3 or Device_Type = 5 ) AND InBox_Id = 0 AND Track_Id=0 AND Field_Id=#{Field_Id} ")
    @Results({
            @Result(property = "Device_Id", column = "Device_Id"),
            @Result(property = "Attributes", column = "Device_Id", many = @Many(select = "com.ruoyi.system.mapper.Nd_ApiMapper.getAttributesByDeviceId"))
    })
    List<Nd_DevicesWrokStatus> getFDevicesByFieldId(String Field_Id);

    //获取已经在股道上布防的铁鞋
    @Select("SELECT nd_devices_work_status.*,nd_track.Track_Number,nd_track.Track_Code,sys_user.user_name as Person_Name,sys_dict_data.dict_label as Postion_Name  FROM nd_devices_work_status " +
            " LEFT JOIN nd_track ON nd_track.Track_Id = nd_devices_work_status.Track_Id " +
            " LEFT JOIN sys_user on nd_devices_work_status.Person_Id = sys_user.user_id " +
//            " LEFT JOIN nd_anti_running_recorder on nd_devices_work_status.Device_Id = nd_anti_running_recorder.Device_Id and nd_anti_running_recorder.qbid = nd_devices_work_status.qbid" +
            " left join sys_dict_data on nd_devices_work_status.Postion = sys_dict_data.dict_value and sys_dict_data.dict_type = " + "'nd_location'" +
            " WHERE Device_Type = 2 AND InBox_Id = 0 AND nd_devices_work_status.Track_Id > 0 AND nd_devices_work_status.Field_Id=#{Field_Id} ")
    @Results({
            @Result(property = "Device_Id", column = "Device_Id"),
            @Result(property = "Attributes", column = "Device_Id", many = @Many(select = "com.ruoyi.system.mapper.Nd_ApiMapper.getAttributesByDeviceId"))
//            @Result(property = "Attributes_imt", column = "Device_Id", many = @Many(select = "com.ruoyi.system.mapper.Nd_ApiMapper.getAttributesByDeviceId"))
    })
    List<Nd_DevicesWrokStatus> getPDevicesByFieldId(String Field_Id);

    //获取铁鞋箱的报警
    @Select("SELECT " +
            " ndal.Device_Id, " +
            " nd.Device_VIN, " +
            " ndal.Attribute_Id, " +
            " nda.Attribute_Name, " +
            " ndal.Attribute_Value, " +
            " nda.Attribute_Code  " +
            "FROM " +
            " nd_devices_attribute_link AS ndal " +
            " INNER JOIN nd_devices nd ON ndal.Device_Id = nd.Device_Id " +
            " INNER JOIN nd_devices_attribute nda ON ndal.Attribute_Id = nda.Attribute_ID  " +
            "WHERE " +
            " nd.Device_Id = #{Device_Id}")
    List<Nd_DeviceAttributeLink> getAttributesByDeviceId(String Device_Id);

    //获取车站配置信息
//    @Select("SELECT " +
//            " nd.Station_Id, " +
//            " nd.Left_Direction, " +
//            " CASE  " +
//            " WHEN sdd.dict_label = '东' THEN ( SELECT dict_value FROM sys_dict_data WHERE dict_label = '西' LIMIT 1 )  " +
//            " WHEN sdd.dict_label = '南' THEN ( SELECT dict_value FROM sys_dict_data WHERE dict_label = '北' LIMIT 1 )  " +
//            " WHEN sdd.dict_label = '西' THEN ( SELECT dict_value FROM sys_dict_data WHERE dict_label = '东' LIMIT 1 )  " +
//            " WHEN sdd.dict_label = '北' THEN ( SELECT dict_value FROM sys_dict_data WHERE dict_label = '南' LIMIT 1 )  " +
//            " WHEN sdd.dict_label = '上行' THEN ( SELECT dict_value FROM sys_dict_data WHERE dict_label = '下行' LIMIT 1 ) " +
//            " WHEN sdd.dict_label = '下行' THEN ( SELECT dict_value FROM sys_dict_data WHERE dict_label = '上行' LIMIT 1 ) " +
//            " ELSE ''  " +
//            " END AS Right_Direction ,  " +
//            " nd.Up_Direction, " +
//            " CASE  " +
//            " WHEN sdd2.dict_label = '东' THEN ( SELECT dict_value FROM sys_dict_data WHERE dict_label = '西' LIMIT 1 )  " +
//            " WHEN sdd2.dict_label = '南' THEN ( SELECT dict_value FROM sys_dict_data WHERE dict_label = '北' LIMIT 1 )  " +
//            " WHEN sdd2.dict_label = '西' THEN ( SELECT dict_value FROM sys_dict_data WHERE dict_label = '东' LIMIT 1 )  " +
//            " WHEN sdd2.dict_label = '北' THEN ( SELECT dict_value FROM sys_dict_data WHERE dict_label = '南' LIMIT 1 )  " +
//            " WHEN sdd2.dict_label = '上行' THEN ( SELECT dict_value FROM sys_dict_data WHERE dict_label = '下行' LIMIT 1 )  " +
//            " WHEN sdd2.dict_label = '下行' THEN ( SELECT dict_value FROM sys_dict_data WHERE dict_label = '上行' LIMIT 1 )  " +
//            " ELSE ''  " +
//            " END AS Down_Direction , " +
//            " sdd.dict_label, " +
//            " sdd.dict_value, " +
//            " sdd.dict_type  " +
//            "FROM " +
//            " nd_station_config nd " +
//            " INNER JOIN sys_dict_data sdd ON nd.Left_Direction = sdd.dict_value  " +
//            " INNER JOIN sys_dict_data sdd2 ON nd.Up_Direction = sdd2.dict_value   " +
//            "WHERE " +
//            " nd.Station_Id = #{Station_Id}  " +
//            "AND sdd.dict_type = 'nd_location' and sdd2.dict_type = 'nd_location'")
    @Select("SELECT \n" +
            "    nd.Station_Id,\n" +
            "    nd.Left_Direction,\n" +
            "    CASE \n" +
            "        WHEN sdd.dict_label = '东' THEN ( SELECT dict_value FROM sys_dict_data WHERE dict_label = '西' LIMIT 1 )\n" +
            "        WHEN sdd.dict_label = '南' THEN ( SELECT dict_value FROM sys_dict_data WHERE dict_label = '北' LIMIT 1 )\n" +
            "        WHEN sdd.dict_label = '西' THEN ( SELECT dict_value FROM sys_dict_data WHERE dict_label = '东' LIMIT 1 )\n" +
            "        WHEN sdd.dict_label = '北' THEN ( SELECT dict_value FROM sys_dict_data WHERE dict_label = '南' LIMIT 1 )\n" +
            "        WHEN sdd.dict_label = '上行' THEN ( SELECT dict_value FROM sys_dict_data WHERE dict_label = '下行' LIMIT 1 )\n" +
            "        WHEN sdd.dict_label = '下行' THEN ( SELECT dict_value FROM sys_dict_data WHERE dict_label = '上行' LIMIT 1 )\n" +
            "        ELSE ''\n" +
            "    END AS Right_Direction,\n" +
            "    nd.Up_Direction,\n" +
            "    CASE \n" +
            "        WHEN sdd2.dict_label = '东' THEN ( SELECT dict_value FROM sys_dict_data WHERE dict_label = '西' LIMIT 1 )\n" +
            "        WHEN sdd2.dict_label = '南' THEN ( SELECT dict_value FROM sys_dict_data WHERE dict_label = '北' LIMIT 1 )\n" +
            "        WHEN sdd2.dict_label = '西' THEN ( SELECT dict_value FROM sys_dict_data WHERE dict_label = '东' LIMIT 1 )\n" +
            "        WHEN sdd2.dict_label = '北' THEN ( SELECT dict_value FROM sys_dict_data WHERE dict_label = '南' LIMIT 1 )\n" +
            "        WHEN sdd2.dict_label = '上行' THEN ( SELECT dict_value FROM sys_dict_data WHERE dict_label = '下行' LIMIT 1 )\n" +
            "        WHEN sdd2.dict_label = '下行' THEN ( SELECT dict_value FROM sys_dict_data WHERE dict_label = '上行' LIMIT 1 )\n" +
            "        ELSE ''\n" +
            "    END AS Down_Direction,\n" +
            "    sdd.dict_label AS Left_Direction_name,\n" +
            "    CASE \n" +
            "        WHEN sdd.dict_label = '东' THEN '西'\n" +
            "        WHEN sdd.dict_label = '南' THEN '北'\n" +
            "        WHEN sdd.dict_label = '西' THEN '东'\n" +
            "        WHEN sdd.dict_label = '北' THEN '南'\n" +
            "        WHEN sdd.dict_label = '上行' THEN '下行'\n" +
            "        WHEN sdd.dict_label = '下行' THEN '上行'\n" +
            "        ELSE ''\n" +
            "    END AS Right_Direction_name,\n" +
            "    sdd.dict_value,\n" +
            "    sdd.dict_type \n" +
            "FROM \n" +
            "    nd_station_config nd\n" +
            "    INNER JOIN sys_dict_data sdd ON nd.Left_Direction = sdd.dict_value\n" +
            "    INNER JOIN sys_dict_data sdd2 ON nd.Up_Direction = sdd2.dict_value\n" +
            "WHERE \n" +
            "    nd.Station_Id = #{Station_Id}\n" +
            "    AND sdd.dict_type = 'nd_location' \n" +
            "    AND sdd2.dict_type = 'nd_location'")
    Nd_StationConfig getStationConfig(String Station_Id);
    //endregion 车站所有设备状态

    //#region  设备数据接口 for-devmsg
    //查询设备当前状态
    @Select("SELECT  " +
            "nd_devices_work_status.Device_Id,  " +
            "nd_devices_work_status.Device_Code,  " +
            "nd_devices_work_status.Device_VIN,  " +
            "nd_devices_work_status.Device_Type,  " +
            "nd_devices_work_status.Track_Id,  " +
            "nd_devices_work_status.Railway_CarNo,  " +
            "nd_devices_work_status.SortNo,  " +
            "nd_devices_work_status.Postion,  " +
            "nd_devices_work_status.Person_Id,  " +
            "nd_devices_work_status.Work_Type_Id,  " +
            "nd_devices_work_status.Operation_Type_Id,  " +
            "nd_devices_work_status.Vbat_Value,  " +
            "nd_devices_work_status.InOutBox,  " +
            "nd_devices_work_status.OpenCloseBox,  " +
            "nd_devices_work_status.IsFree,  " +
            "nd_devices_work_status.Inbox_Id,  " +
            "nd_devices_work_status.Station_Id,  " +
            "nd_devices_work_status.zmlm,  " +
            "nd_devices_work_status.create_by,  " +
            "nd_devices_work_status.create_time,  " +
            "nd_devices_work_status.update_by,  " +
            "nd_devices_work_status.update_time,  " +
            "nd_devices_work_status.DevTemperature,  " +
            "nd_devices_work_status.IsOnline,  " +
            "nd_devices_work_status.VbatPercent,  " +
            "nd_devices_work_status.Field_Id  " +
            "FROM  " +
            "nd_devices_work_status   " +
            "WHERE  " +
            "nd_devices_work_status.Device_Id = #{Device_Id}")
    Nd_DevicesWrokStatus selectDeviceStatus_devmsg(String Device_Id);

    //查询某个设备的最后一次防溜记录
    @Select("SELECT " +
            "nd_anti_running_recorder.Anti_Recorder_Id, " +
            "nd_anti_running_recorder.Station_Id, " +
            "nd_anti_running_recorder.zmlm, " +
            "nd_anti_running_recorder.Device_Id, " +
            "nd_anti_running_recorder.Track_Id, " +
            "nd_anti_running_recorder.Railway_CarNo, " +
            "nd_anti_running_recorder.SortNo, " +
            "nd_anti_running_recorder.Postion, " +
            "nd_anti_running_recorder.Work_Type_Id, " +
            "nd_anti_running_recorder.Person_Id, " +
            "nd_anti_running_recorder.Operation_Type_Id, " +
            "nd_anti_running_recorder.zwh, " +
            "nd_anti_running_recorder.beizhu, " +
            "nd_anti_running_recorder.create_by, " +
            "nd_anti_running_recorder.create_time, " +
            "nd_anti_running_recorder.update_by, " +
            "nd_anti_running_recorder.update_time, " +
            "nd_anti_running_recorder.qbid " +
            "FROM " +
            "nd_anti_running_recorder " +
            "WHERE " +
            "nd_anti_running_recorder.Device_Id = #{DeviceId} ORDER BY update_time DESC LIMIT 1")
    Nd_AntiRunningRecorder selectAntiRunningRecorder_devmsg(String DeviceId);

    /**
     * 更新单个设备状态 for设备消息 nd_devices_work_status
     **/
//    @Update("UPDATE nd_devices_work_status SET " +
////            "Device_Code= #{devStatus.Device_Code}, " +
////            "Device_VIN= #{devStatus.Device_VIN}, " +
////            "Device_Type= #{devStatus.Device_Type}, " +
//            "Track_Id= #{devStatus.Track_Id}, " +
//            "Railway_CarNo= #{devStatus.Railway_CarNo}, " +
//            "SortNo= #{devStatus.SortNo}, " +
//            "Postion= #{devStatus.Postion}, " +
////            "Person_Id= #{devStatus.Person_Id}, " +
//            "Work_Type_Id= #{devStatus.Work_Type_Id}, " +
//            "Operation_Type_Id= #{devStatus.Operation_Type_Id}, " +
//            "Vbat_Value= #{devStatus.Vbat_Value}, " +
//            "OpenCloseBox= #{devStatus.OpenCloseBox}, " +

    /// /            "Inbox_Id= #{devStatus.Inbox_Id}, " +
    /// /            "Station_Id= #{devStatus.Station_Id}, " +
//            "create_by= #{devStatus.create_by}, " +
//            "create_time= #{devStatus.create_time}, " +
//            "update_by= #{devStatus.update_by}, " +
//            "update_time= #{devStatus.update_time}, " +
//            "placement_time= #{devStatus.placement_time}, " +
//            "DevTemperature= #{devStatus.DevTemperature}, " +
//            "IsOnLine= #{devStatus.IsOnLine}" +
//            "WHERE Device_Id = #{devStatus.Device_Id}")
    @Update("<script>" +
            "UPDATE nd_devices_work_status SET " +
            "Track_Id = #{devStatus.Track_Id}, " +
            "Railway_CarNo = #{devStatus.Railway_CarNo}, " +
            "SortNo = #{devStatus.SortNo}, " +
            "Postion = #{devStatus.Postion}, " +
            "Work_Type_Id = #{devStatus.Work_Type_Id}, " +
            "Operation_Type_Id = #{devStatus.Operation_Type_Id}, " +
            "Vbat_Value = #{devStatus.Vbat_Value}, " +
            "<if test='devStatus.OpenCloseBox != null and devStatus.OpenCloseBox != \"\"'>" +
            "OpenCloseBox = #{devStatus.OpenCloseBox}, " +
            "</if>" +
//            "OpenCloseBox = #{devStatus.OpenCloseBox}, " +
            "create_by = #{devStatus.create_by}, " +
            "create_time = #{devStatus.create_time}, " +
            "update_by = #{devStatus.update_by}, " +
            "update_time = #{devStatus.update_time}, " +
            "<if test='devStatus.placement_time != null'>" +
            "placement_time = #{devStatus.placement_time}, " +
            "</if>" +
            "<if test='devStatus.no_box_state != null'>" +
            "no_box_state = #{devStatus.no_box_state}, " +
            "</if>" +
            "DevTemperature = #{devStatus.DevTemperature}, " +
            "update_time = NOW(), " +
            "IsOnLine = #{devStatus.IsOnLine} " +
            "WHERE Device_Id = #{devStatus.Device_Id}" +
            "</script>")
    void updateDeviceStatus_devmsg(@Param("devStatus") Nd_DevicesWrokStatus devStatus);

    /**
     * 更新箱内设备信息 for设备消息 主要是关箱后，箱内的多只铁鞋状态一并更新为在箱内
     **/
    @Update("<script>" +
            "<foreach collection='objs' item='obj' separator=';'>" +
            "UPDATE nd_devices_work_status SET " +
            "Inbox_Id = #{obj.Inbox_Id}, " +
            "Vbat_Value = #{obj.Vbat_Value}, " +
            "VbatPercent = #{obj.VbatPercent}, " +
            "IsFree = #{obj.IsFree}," +
            "InOutBox = #{obj.InOutBox}, " +
            "<if test='obj.out_time != null'>" +
            "out_time = #{obj.out_time}, " +
            "</if>" +
            "<if test='obj.in_time != null'>" +
            "in_time = #{obj.in_time}, " +
            "</if>" +
            "update_time = NOW() " +
            "WHERE Device_VIN = #{obj.Device_VIN} AND zmlm = UPPER(#{obj.zmlm}) " +
            "</foreach>" +
            "</script>")
    void updateDevicesStatus_devmsg(@Param("objs") List<Nd_DevicesWrokStatus> objs);

    @Update("<script>" +
            "<foreach collection='objs' item='obj' separator=';'>" +
            "UPDATE nd_devices_work_status SET " +
            "out_time = #{obj.out_time}, " +
            "update_time = NOW(), " +
            "in_time = #{obj.in_time}, " +
            "update_time = NOW() " +
            "WHERE Device_VIN = #{obj.Device_VIN} " +
            "</foreach>" +
            "</script>")
    void updateInOutTimeStatus(@Param("objs") List<Nd_DevicesWrokStatus> objs);

    @Update("UPDATE nd_devices_work_status SET " +
            "out_time = #{obj.out_time}, " +
            "update_time = NOW(), " +
            "in_time = #{obj.in_time}, " +
            "update_time = NOW() " +
            "WHERE Device_Id = #{obj.Device_Id} ")
    void updateInOutTimeStatus2(@Param("obj") Nd_DevicesWrokStatus obj);
//    void updateInOutTimeStatus2(@Param("objs") Nd_DevicesWrokStatus objs);

    /**
     * 根据设备 ID 列表更新设备的出入库时间为 null 并更新更新时间
     *
     * @param deviceIds 设备 ID 列表
     */
    @Update("<script>" +
            "UPDATE nd_devices_work_status " +
            "SET " +
            "out_time = null, " +
            "in_time = null, " +
            "update_time = NOW() " +
            "WHERE Device_Id IN " +
            "<foreach item='item' index='index' collection='deviceIds' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    void updateInOutTimeToNullByDeviceIds(@Param("deviceIds") List<Long> deviceIds);


    //更新设备报警属性状态
    @Update("UPDATE nd_devices_attribute_link " +
            "SET  " +
            "Attribute_Value = #{Attribute_Value}  " +
            "WHERE " +
            " Device_Id = #{Device_Id}  " +
            " AND Attribute_Id = #{Attribute_Id};")
    void updateDeviceAttributeLink(Nd_DeviceAttributeLink nd_deviceAttributeLink);

    //    @Select("select * from nd_anti_running_recorder.*,sys_user.user_name as Person_Name " +
//            " LEFT JOIN sys_user on nd_anti_running_recorder.Person_Id = sys_user.user_id " +
//            "where nd_anti_running_recorder.qbid = #{qbid} and Device_Id = 0")
    @Select("SELECT " +
            "    nd_anti_running_recorder.*, " +
            "    sys_user.user_name as Person_Name " +
            "FROM " +
            "    nd_anti_running_recorder " +
            "LEFT JOIN " +
            "    sys_user ON nd_anti_running_recorder.Person_Id = sys_user.user_id " +
            "WHERE " +
            "    nd_anti_running_recorder.qbid = #{qbid} " +
            "    AND nd_anti_running_recorder.Device_Id = 0")
    List<RLTrainRecoder> selectAntiRunningRecorderByTypeAndTrainId(String qbid);

    @Update("UPDATE nd_train_recoder " +
            "SET  " +
            "is_open = 0 " +
            "WHERE " +
            " qbid = #{qbid}  ")
    boolean updateTrainIsOpen(String qbid);

    @Update("UPDATE nd_anti_running_recorder " +
            "SET  " +
            "is_remove = 0 " +
            "WHERE " +
            " qbid = #{qbid}  ")
    boolean updateAntiRunningIsRemove(String qbid);

    //    @Select("SELECT * \n" +
//            "FROM nd_alarm_recorder\n" +
//            "WHERE nd_alarm_recorder.Station_Id = #{stationId} and Alarm_Time >= NOW() - INTERVAL 10 SECOND;")
    @Select("SELECT\n" +
            "\t*,\n" +
            "\tnd_alarm.Alarm_Name AS alarmName,\n" +
            "\tnd_devices.Device_Code AS deviceCode,\n" +
            "\tsys_dict_data.dict_label AS deviceTypeName \n" +
            "FROM\n" +
            "\tnd_alarm_recorder\n" +
            "\tLEFT JOIN nd_alarm ON nd_alarm.Alarm_Id = nd_alarm_recorder.Alarm_Type\n" +
            "\tLEFT JOIN nd_devices ON nd_alarm_recorder.Device_Id = nd_devices.Device_Id\n" +
            "\tLEFT JOIN sys_dict_data ON nd_devices.Device_Type = sys_dict_data.dict_value and sys_dict_data.dict_type = 'nd_devtype'\n" +
            "WHERE\n" +
            "\tnd_alarm_recorder.Station_Id = #{stationId} \n" +
            "\tAND nd_alarm_recorder.IS_Relieve = 2\n" +
            "\tAND nd_alarm_recorder.Alarm_Time >= NOW( ) - INTERVAL 10 SECOND;")
    List<Nd_AlarmRecorder> selectVoiceAlarm(String stationId);

    @Select("SELECT\n" +
            "\t*,\n" +
            "\tnd_alarm.Alarm_Name AS alarmName,\n" +
            "\tnd_devices.Device_Code AS deviceCode,\n" +
            "\tsys_dict_data.dict_label AS deviceTypeName \n" +
            "FROM\n" +
            "\tnd_alarm_recorder\n" +
            "\tLEFT JOIN nd_alarm ON nd_alarm.Alarm_Id = nd_alarm_recorder.Alarm_Type\n" +
            "\tLEFT JOIN nd_devices ON nd_alarm_recorder.Device_Id = nd_devices.Device_Id\n" +
            "\tLEFT JOIN sys_dict_data ON nd_devices.Device_Type = sys_dict_data.dict_value and sys_dict_data.dict_type = 'nd_devtype'\n" +
            "WHERE\n" +
            "\tnd_alarm_recorder.Station_Id = #{stationId} \n" +
            "\tAND nd_alarm_recorder.IS_Relieve = 2 ")
    List<Nd_AlarmRecorder> selectVoiceAlarm2(String stationId);

    @Select("SELECT\n" +
            "\t*,\n" +
            "\tnd_alarm.Alarm_Name AS alarmName,\n" +
            "\tnd_devices.Device_Code AS deviceCode,\n" +
            "\tsys_dict_data.dict_label AS deviceTypeName \n" +
            "FROM\n" +
            "\tnd_alarm_recorder\n" +
            "\tLEFT JOIN nd_alarm ON nd_alarm.Alarm_Id = nd_alarm_recorder.Alarm_Type\n" +
            "\tLEFT JOIN nd_devices ON nd_alarm_recorder.Device_Id = nd_devices.Device_Id\n" +
            "\tLEFT JOIN sys_dict_data ON nd_devices.Device_Type = sys_dict_data.dict_value AND sys_dict_data.dict_type = 'nd_devtype'\n" +
            "WHERE\n" +
            "\tnd_alarm_recorder.shifts_id = #{changeShiftsId} ")
    List<Nd_AlarmRecorder> selectVoiceAlarmByShiftsId(@Param("changeShiftsId") Integer changeShiftsId);


    @Select("select * from nd_devices_work_status where nd_devices_work_status.Station_Id = #{station_id}")
    List<Nd_DevicesWrokStatus> selectAllDevByStationId(@Param("station_id") String station_id);


    @Select("select * from nd_devices_work_status where nd_devices_work_status.Station_Id = #{station_id}")
    List<Nd_DevicesWrokStatus2> selectAllDevByStationId2(@Param("station_id") String station_id);

    @Insert("<script>" +
            "INSERT INTO nd_change_shifts_detail (" +
            "Change_Shifts_Detail_Id, Change_Shifts_Id, Device_Id, Device_Code, Device_VIN, Device_Type, Track_Id, " +
            "Railway_CarNo, SortNo, Postion, Person_Id, qbid, Work_Type_Id, Operation_Type_Id, Vbat_Value, " +
            "InOutBox, OpenCloseBox, IsFree, Inbox_Id, Station_Id, zmlm, create_by, create_time, update_by, " +
            "update_time, DevTemperature, IsOnline, VbatPercent, Field_Id, placement_time, out_time, in_time" +
            ") VALUES " +
            "<foreach collection='entities' item='entity' separator=','>" +
            "(#{entity.Change_Shifts_Detail_Id}, #{entity.Change_Shifts_Id}, #{entity.Device_Id}, #{entity.Device_Code}, " +
            "#{entity.Device_VIN}, #{entity.Device_Type}, #{entity.Track_Id}, #{entity.Railway_CarNo}, #{entity.SortNo}, " +
            "#{entity.Postion}, #{entity.Person_Id}, #{entity.qbid}, #{entity.Work_Type_Id}, #{entity.Operation_Type_Id}, " +
            "#{entity.Vbat_Value}, #{entity.InOutBox}, #{entity.OpenCloseBox}, #{entity.IsFree}, #{entity.Inbox_Id}, " +
            "#{entity.Station_Id}, #{entity.zmlm}, #{entity.create_by}, #{entity.create_time}, #{entity.update_by}, " +
            "#{entity.update_time}, #{entity.DevTemperature}, #{entity.IsOnline}, #{entity.VbatPercent}, #{entity.Field_Id}, " +
            "#{entity.placement_time}, #{entity.out_time}, #{entity.in_time})" +
            "</foreach>" +
            "</script>")
    int addndChangeShiftsDetails(@Param("entities") List<NdChangeShiftsDetail> entities);

    @Select("select * from nd_change_shifts_detail where nd_change_shifts_detail.change_shifts_id = #{change_shifts_id}")
    List<Nd_DevicesWrokStatus> selectshiftingLogDetail(Integer change_shifts_id);

    @Update("<script>" +
            "UPDATE nd_alarm_recorder " +
            "SET shifts_id = #{Change_Shifts_Id} " +
            "WHERE Alarm_Record_Id IN " +
            "<foreach item='item' index='index' collection='alarmIds' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    int updateAlarmAddShiftsId(@Param("alarmIds") List<Integer> alarmIds,@Param("Change_Shifts_Id") Integer id);

    /**
     * 根据缺失的设备 ID 列表统计不同设备类型的数量
     * @param missingDeviceIds 缺失的设备 ID 列表
     * @return 包含设备类型和对应数量的映射
     */
    @Select("<script>" +
            "SELECT nd_devices.Device_Type, COUNT(1) as device_count " +
            "FROM nd_devices " +
            "WHERE nd_devices.Device_Id IN " +
            "<foreach item='item' index='index' collection='missingDeviceIds' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "GROUP BY nd_devices.Device_Type" +
            "</script>")
    Map<String, Integer> selectMissingDevnum(@Param("missingDeviceIds") List<String> missingDeviceIds);

    @Select("select * from nd_devices_work_status where Device_VIN = #{device_vin} and zmlm = #{zmlm}")
    Nd_DevicesWrokStatus getDeviceByDeviceVINAndZmlm(@Param("device_vin") String device_vin, @Param("zmlm") String zmlm);


    //#endregion 设备数据接口

//    /** 下面目前没有用到
//     * 批量插入或者更新  nd_devices_work_status  主要是关箱后，箱内的多只铁鞋状态一并更新为在箱内
//     * **/
//    @Insert({
//            "<script>",
//            "INSERT INTO nd_devices_work_status ("+
//                    "Device_Id, " ,
////                   "Device_Code, " +
////                   "Device_VIN, " +
////                   "Device_Type, " +
////                   "Track_Id, " +
////                   "Railway_CarNo, " +
////                   "SortNo, " +
////                   "Postion, " +
////                   "Person_Id, " +
//            "Work_Type_Id, " +
////                   "Operation_Type_Id, " +
////                   "Vbat_Value, " +
////                   "InOutBox, " +
////                   "OpenCloseBox, " +
////                   "IsFree, " +
//                    "Inbox_Id, " ,
//            "Station_Id, " ,
//            "zmlm, " ,
////                   "create_by, " +
////                   "create_time, " +
////                   "update_by, " +
////                   "update_time, " +
////                   "DevTemperature, " +
//            "IsOnLine" ,
//            ") VALUES",
//            "<foreach collection='devStatusArr' item='devStatus' separator=','>",
//            "("+
//                    "#{devStatus.Device_Id}, ",
//            "#{devStatus.Work_Type_Id}, ",
//            "#{devStatus.Inbox_Id}, ",
//            "#{devStatus.Station_Id},",
//            "#{devStatus.zmlm},",
//            "#{devStatus.IsOnline}",
//            ")",
//            "</foreach>",
//            "ON DUPLICATE KEY UPDATE ",
//            //"Device_Id = VALUES(Device_Id),"+
//            "Inbox_Id = VALUES(Inbox_Id),",
//            "Station_Id = VALUES(Station_Id),",
//            "zmlm = VALUES(zmlm),",
//            "IsOnLine = VALUES(IsOnline)",
//            "</script>"
//    })
//    void updateDevsStatus(@Param("devStatusArr") List<Nd_DevicesWrokStatus> devStatusArr);

//    /**
//     * 查询某个场的所有设备  目前未使用
//     */
//    @Select("SELECT nd_devices_work_status.*,nd_track.Track_Number,nd_track.Track_Code " +
//            " FROM nd_devices_work_status " +
//            " LEFT JOIN nd_track ON nd_track.Track_Id = nd_devices_work_status.Track_Id " +
//            "WHERE nd_devices_work_status.Field_Id = #{Field_Id} AND nd_devices_work_status.Device_Type = #{Device_Type}")
//    List<Nd_DevicesWrokStatus> getDevicesByFiled(@Param("Field_Id") String Field_Id,@Param("Device_Type") String Device_Type);
}
